package com.chuanjiabao.wisdom.util.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;

import com.bumptech.glide.Glide;
import com.chuanjiabao.wisdom.R;
import com.chuanjiabao.wisdom.databinding.DialogDownloadProgressHintBinding;
import com.chuanjiabao.wisdom.databinding.DialogPermissionHintBinding;

import java.util.concurrent.TimeUnit;

import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class PermissionDialog extends BaseDialog {

    private Disposable disposable;
    private DialogPermissionHintBinding binding;

    public PermissionDialog(Context context) {
        super(context, R.style.NoAnimeDialog);
        binding = DataBindingUtil.inflate(
                LayoutInflater.from(context),
                R.layout.dialog_permission_hint,
                null,
                false
        );
        binding.setDialog(this);
        setContentView(binding.getRoot());
        setCanceledOnTouchOutside(false);
        setCancelable(false);

        disposable = Completable.timer(2000, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this::dismiss);
    }

    @SuppressLint("CheckResult")
    public PermissionDialog setHint(String hint) {
        binding.tvModuleHint.setText(hint);
        return this;
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (disposable != null) disposable.dispose();
    }

}


